<?php
$mysqli= new mysqli("localhost","root","root","db_blw");
if($mysqli->connect_errno){
    die();
}
$title=$_GET["title"];
$nye=$_GET["nye"];
$nye=($nye-1)*4;
$state=$_GET["state"];

if($state == "1" ){

    $sql="select * from t_categorylist where title like '%{$title}%' order by Id asc limit {$nye},4";

}elseif($state == "-1" ){

    $sql="select * from t_categorylist where title like '%{$title}%' order by Id desc limit {$nye},4";

}elseif($state == "2" ){

    $sql="select * from t_categorylist where title like '%{$title}%' order by comment asc limit {$nye},4";

}elseif($state == "-2" ){

    $sql="select * from t_categorylist where title like '%{$title}%' order by comment desc limit {$nye},4";

}elseif($state == "3" ){

    $sql="select * from t_categorylist where title like '%{$title}%' order by price asc limit {$nye},4";

}elseif($state == "-3" ){
    $sql="select * from t_categorylist where title like '%{$title}%' order by price desc limit {$nye},4";
}

$result=$mysqli->query($sql);

while($row = $result->fetch_assoc()){
    $data[] = $row;
}

if($result->num_rows){
    $data=array("err"=>'1',"data"=>$data);
} else {
    $data=array("err"=>'0',"data"=>"{}");
}


echo json_encode($data);



